package com.gexiaobao.pigeon.ui.adapter

import android.annotation.SuppressLint
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.model.bean.BaseMultiQuickItem
import com.gexiaobao.pigeon.app.model.bean.ShopOrderListResponse
import com.gexiaobao.pigeon.app.util.ImageLoaderManager
import com.gexiaobao.pigeon.databinding.ItemGoodsOrderMineOrderBinding
import com.gexiaobao.pigeon.databinding.ItemSingleGoodBinding
import com.makeramen.roundedimageview.RoundedImageView

/**
 * @author: hxw
 * @date  : 2023/2/2
 * @desc  :
 */
class GoodsOrderItemAdapter(data: ArrayList<ShopOrderListResponse.ListBean.ListStore.ListGoods>) :
    BaseMultiItemQuickAdapter<ShopOrderListResponse.ListBean.ListStore.ListGoods, BaseViewHolder>(data) {

    init {
        addItemType(BaseMultiQuickItem.FIRST_TYPE, R.layout.item_goods_order_mine_order)
        addItemType(BaseMultiQuickItem.SECOND_TYPE, R.layout.item_single_good)
    }

    @SuppressLint("SetTextI18n")
    override fun convert(holder: BaseViewHolder, item: ShopOrderListResponse.ListBean.ListStore.ListGoods) {
//        val binding = DataBindBaseViewHolder.getBinding(holder) as ItemGoodsOrderMineOrderBinding
//        binding.data = item
//        binding.executePendingBindings()//防止列表抖动

        when (holder.itemViewType) {
            0 -> {
                val ivItemGoodsOrderImageIcon = holder.getView<RoundedImageView>(R.id.ivItemGoodsOrderImageIcon)
                ImageLoaderManager.loadRoundImageOrEmpty(context, item.specImg, ivItemGoodsOrderImageIcon, 10, R.drawable.shop_product_def)
            }

            1 -> {
                holder.setText(R.id.itemSingleGoodName, item.goodName)
                holder.setText(R.id.itemSingleGoodSpecName, item.specName)
                val ivItemGoodsOrderImageIcon = holder.getView<RoundedImageView>(R.id.ivItemMyGoodsOrderImageIcon)
                ImageLoaderManager.loadRoundImageOrEmpty(context, item.specImg, ivItemGoodsOrderImageIcon, 10, R.drawable.shop_product_def)
            }
        }
    }
}